﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tunnel.Devices.DeviceEntity
{
    
    public partial class FanForm : Form
    {
        Fan fan = new Fan();
        public FanForm(Fan fan)
        {
            InitializeComponent();
            this.fan = fan;

            try
            {
                if (!Global.PlcStatus[fan.Protocol])
                {
                    ok.Enabled = false;
                    ok.Text = "故障";
                }
            }
            catch { }

            switch (fan.StatusDescription)
            {
                case "正转": rbZZ.Checked = true; rbFZ.Enabled = false; break;
                case "反转": rbFZ.Checked = true; rbZZ.Enabled = false; break;
                case "停止": rbTZ.Checked = true;break;
            }
            lbName.Text = fan.Name;
            label1.Text = $"{fan.ZzName}  {fan.FzName}  {fan.TzName}";
        }

        private void ok_Click(object sender, EventArgs e)
        {
            if(rbZZ.Checked==true)
            {
                fan.SendCommand(CommandType.风机正转);
                //fan.StatusDescription = "正转";
            }
            if(rbFZ.Checked==true)
            {
                fan.SendCommand(CommandType.风机反转);
                //fan.StatusDescription = "反转";
            }
            if(rbTZ.Checked==true)
            {
                fan.SendCommand(CommandType.风机停止);
                //fan.StatusDescription = "停止";
            }
            this.Close();
        }

        private void cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
